# Contributor: Gavin Henry <ghenry@sentrypeer.org>
# Maintainer: Gavin Henry <ghenry@sentrypeer.org>
pkgname=opendht
pkgver=3.1.7
pkgrel=3
pkgdesc="C++17 Distributed Hash Table implementation"
url="https://github.com/savoirfairelinux/opendht"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	argon2-dev
	asio-dev
	cmake
	cython
	fmt-dev
	gnutls-dev
	http-parser-dev
	jsoncpp-dev
	msgpack-cxx-dev
	nettle-dev
	openssl-dev
	py3-setuptools
	python3-dev
	readline-dev
	restinio-dev
	samurai
	"
checkdepends="cppunit-dev"
depends_dev="fmt-dev"
subpackages="py3-$pkgname:_py3 $pkgname-libs $pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/savoirfairelinux/opendht/archive/refs/tags/v$pkgver.tar.gz"
# tests require a quiet environment or network reads don't match
options="!check"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DOPENDHT_C=ON \
		-DOPENDHT_TOOLS=ON \
		-DOPENDHT_PYTHON=ON \
		-DOPENDHT_HTTP=ON \
		-DOPENDHT_PUSH_NOTIFICATIONS=ON \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

libs() {
	default_libs
	amove usr/lib/libopendht-c.so
}

_py3() {
	pkgdesc="$pkgdesc (python bindings)"
	amove usr/lib/python*
	amove usr/bin/dhtcluster
}

sha512sums="
c89e8276520f94daa31a5c07e6725ba6b8f3daa2fa118914f61394b879b63dce2e0ab462e35af31d40ebd15d1feb119236b4a791dff683486ed7ccd1d0589756  opendht-3.1.7.tar.gz
"
